/**
 * @param {number} n
 * @return {number}
 */
var numberOf2sInRange = function (n) {
  let count = 0, res = []
  for (let i = 0; i <= n; i++) {
    let ch = i.toString()
    if (ch.indexOf('2') != -1) {
      for (let j = 0; j < ch.length; ch++) {
        res.push(ch)
        if (ch[j] == '2') count++
      }
    }
  }

  console.log(res);
  return count
};

numberOf2sInRange(22)